package com.zqwm.fly.types;

import org.json.JSONObject;

/**
 * @author songyifei
 */
public class Result {

    Integer code;
    String msg;
    JSONObject json = new JSONObject();

    public Result() {
        code = -1;
        msg = "unknown";
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public int getCode(){return code;}

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setJson(JSONObject json){this.json= json;}

    public void addField(String name, Object content ){
        json.put(name, content);
    }
    public void addField(Object content ){json.put("content", content);}

    public void throwsException(String msg)
    {
        this.code = ResultType.EXCEPTION.getValue();
        this.msg = msg;
    }

    @Override
    public String toString() {
        json.put("result", code);
        json.put("msg", msg);
        return json.toString();
    }
}
